home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / OS⁄Toolbox / Sound Input Driver Ex. 1.0 / HackRecorderInit.a < prev    next >
Encoding:
Text File  |  1991-04-08  |  7.7 KB  |  243 lines  |  [TEXT/MPS ]

  1. ;====================================================================================
  2. ;
  3. ;    HackRecorderInit.a
  4. ;    
  5. ;    Copyright © 1990 Apple Computer, Inc.
  6. ;    
  7. ;    Sound Input Driver Example
  8. ;
  9. ;    Revision History
  10. ;
  11. ;        04/01/91    No changes except added this comment line: Submitted as item for developer CD.
  12. ;        11/19/90    First created.
  13. ;
  14. ;====================================================================================
  15.  
  16.             INCLUDE 'Traps.a'
  17.             INCLUDE 'SysErr.a'
  18.             INCLUDE 'SysEqu.a'
  19.             INCLUDE    'Sound.a'
  20.  
  21.             CASE    OBJ
  22.             STRING    PASCAL
  23.             MACHINE    MC68000
  24.  
  25. Lvl7Mask    EQU        $0700        ; used to keep out all non-maskable interrupts.
  26.  
  27. ;_______________________________________________________________________
  28. ;
  29. ; Routine:        Start
  30. ;    Start is the entry point of this INIT.
  31. ;    It loads the 'DRVR' resource into memory, finds an available "slot" in
  32. ;    the Unit Table (properly expanding it if necessary), and installs the driver.
  33. ;
  34. ; Registers Used:
  35. ;            A0    --  Temp, Ptr to DCE
  36. ;            A1  --  Ptr to Unit Table
  37. ;            A2  --  Used to JSR to driver's Open routine
  38. ;            A3    --  Handle to DRVR 
  39. ;                
  40. ;            D0  --  Temp, Driver RefNum
  41. ;            D1  --  Offset into Unit Entry Table where we install the driver
  42. ;            D2  --  Temp
  43. ;            D3  --  Used to save Driver RefNum for SPBSignIn
  44. ;_______________________________________________________________________
  45.  
  46. Start        Main    Export
  47.                                     
  48.             ; Get the DRVR resource and keep it in memory
  49.                             
  50.             CLR.L    -(SP)                ; push space for handle result on stack
  51.             MOVE.L    #'DRVR', -(SP)        ; push ResType param on stack
  52.             LEA        @drvrName, A0
  53.             MOVE.L    A0, -(SP)            ; push ptr to name string on stack
  54.             _GetNamedResource            ; get handle to our DRVR in memory
  55.             MOVE.L    (SP)+, A3            ; get handle off stack 
  56.             MOVE.L    A3, D0                ; AND test it
  57.             BEQ        @outOfHere
  58.             MOVE.L    A3, -(SP)            ; handle is good so push it back on stack
  59.             _DetachResource
  60.             MOVE.L    A3, A0
  61.             _MoveHHi                    ; get it up out of the way before locking it
  62.             MOVE.L    A3, A0                ; get handle to our DRVR
  63.             _HLock                        ; lock down the driver
  64.             
  65.             ; Find a slot for the driver & expand the unit table if necessary
  66.                         
  67.             MOVE.W    #(48*4),D1            ; offset into unit table for unit 48
  68.             MOVE.W    #-49,D0                ; refnum matching unit -49
  69.                         
  70.             MOVEM.L    A0/D0, -(SP)        ; save regs that GetPtrSize uses
  71.             MOVEA.L    UTableBase, A0        ; GetPtrSize wants Ptr in A0
  72.             _GetPtrSize
  73.             MOVE.L    D0, D2                ; Save Result        
  74.             MOVEM.L    (SP)+, A0/D0        ; Restore regs
  75.             BMI        @outOfHere            ; error
  76.             LSR.W    #1, D2                 
  77.             LSR.W    #1, D2                ; Div by 4 to compare with Unit Table Size
  78.             MOVE.W    UnitNtryCnt, D3
  79.             CMP.W    D2, D3
  80.             BEQ.S        @UnitNtryCntIsCorrect
  81.             MOVE.W    D2, UnitNtryCnt            ; Fix it
  82.             
  83. @UnitNtryCntIsCorrect
  84.             CMP.W    #48, UnitNtryCnt
  85.             BGT.S    @LookForSlot
  86.             
  87.             ; Resize unit table
  88.  
  89.             MOVEM.L    D0, -(SP)                ; save D0, ResizeUnitTable uses D0, but we're using it
  90.             MOVE.W    UnitNtryCnt, D2
  91.             ADD.W    #16, D2                    ; Now add 16 more slots to Unit Table
  92.             MOVE.W    D2, -(SP)                ; push requested # of SLOTS for new Unit Table
  93.             JSR        ResizeUnitTable            ; Resize Unit table & update UnitNtryCnt
  94.             ADDQ    #2, SP                    ; balance stack
  95.             MOVE.W    D0, D0
  96.             MOVEM.L    (SP)+, D0
  97.             BMI        @outOfHere                ; error
  98.                         ; NOW:
  99.                         ; D1 has offset into unit table for unit #48
  100.                         ; D0 has refnum matching unit #-49
  101.                         ; AND, we know that this spot is avaiable, because we just created it.
  102.                         ; SO...
  103.             BRA.S    @emptyEntry
  104.  
  105.  
  106. @LookForSlot            
  107.             MOVE.L    UTableBase,A1        ; get ptr to unit table
  108. @nextEntry    TST.L    0(A1,D1)            ; check for empty unit table entry[D1/4]
  109.             BEQ.S    @emptyEntry
  110.             ADDQ.W    #4, D1                ; inc unit table offset to next entry
  111.             SUBQ.W    #1, D0                ; dec refNum to match inc'ed unit number
  112.             MOVE.W    D1, D2
  113.             LSR.W    #1, D2                 
  114.             LSR.W    #1, D2                ; Div by 4 to compare with Unit Table Size
  115.             CMP.W    UnitNtryCnt, D2
  116.             BGE.S    @SpotNotFound
  117.             BRA.S    @nextEntry
  118.  
  119. @SpotNotFound
  120.             ; Resize unit table
  121.             
  122.             MOVE.W    UnitNtryCnt, D2
  123.             ADD.W    #16, D2    
  124.             MOVE.W    D2, -(SP)                ; push requested # of SLOTS for new Unit Table
  125.             JSR        ResizeUnitTable            ; Resize Unit table & update UnitNtryCnt
  126.             ADDQ    #2, SP                    ; balance stack
  127.             TST.W    D0
  128.             BMI.S    @outOfHere                ; error
  129.             
  130.             MOVE.W    UnitNtryCnt, D1            ; get max SLOTS
  131.             SUB.W    #16, D1                    ; we want the first one that we just created
  132.             MOVE.W    D1, D0                    ; save in D0 for refNum 
  133.             LSL.W    #1, D1                     ; Mul by 4 
  134.             LSL.W    #1, D1                    ;    to get offset into UTable
  135.             ADDQ    #1, D0                    ; Update coresponding refnum
  136.             NEG.W    D0
  137.                         ; NOW:
  138.                         ; D1 has offset into unit table
  139.                         ; D0 has refnum matching unit
  140.                         ; AND, we know that this spot is avaiable, because we just created it.
  141.                         ; SO...
  142. ;            BRA.S    @emptyEntry                ; let this drop through
  143.             
  144. @emptyEntry
  145.             MOVE.L    D0, D4                        ; sock away the refNum so our DRVR can get it later
  146.                                                 
  147.             MOVE.L    A3,A0                        ; get handle to our DRVR
  148.             MOVE.L    (A0),A0                        ; get Ptr to our DRVR
  149.             MOVE.L    UTableBase,A1                ; get ptr to unit table
  150.             MOVE.L    A1,-(SP)                    ; save unit table ptr
  151.             _DrvrInstall    ,sys                ; A0=Ptr to our DRVR, D0=DRVR refNum to use
  152.             
  153.             MOVE.L    (SP)+,A1                    ; restore unit table ptr
  154.             MOVE.L    0(A1,D1),A0                    ; get handle to DCEntry from unit table
  155.             MOVE.L    A0,-(SP)                    ; save DCEntry ptr
  156.             _HLock                                ; lock down the DCE (handle is still on stack)
  157.             
  158.             MOVE.L    (SP)+,A0                    ; restore DCEntry ptr
  159.             MOVE.L    (A0),A0                        ; get Ptr to DCE
  160.             MOVE.L    A3,A1                        ; get handle to DRVR 
  161.             MOVE.L    (A1),A1                        ; get Ptr to DRVR
  162.             MOVE.L    A1,dCtlDriver(A0)            ; and into DCE
  163.             MOVE.W    drvrFlags(A1),dCtlFlags(A0)    ; put drvrFlags into DCE
  164.             
  165.             MOVE.W    drvrDelay(A1),dCtlDelay(A0)    ; put drvrDelay into DCE
  166.             MOVE.W    drvrEMask(A1),dCtlEMask(A0)    ; put drvrEMask into DCE
  167.             MOVE.W    drvrMenu(A1),dCtlMenu(A0)    ; put drvrMenu  into DCE
  168.  
  169.             MOVEQ.L    #0,D0
  170.             MOVE.W    drvrOpen(A1),D0                ; get offset to open routine
  171.             ADD.L    A1,D0                        ; get Ptr to open routine
  172.             MOVE.L    D0,A2                        ; put it in an A reg so we can JSR to it
  173.  
  174.             MOVE.L    A0,A1                        ; put DCE into A1 to fake out Open DRVR call
  175.             BSET.B    #dOpened,dCtlFlags+1(A1)    ; set dCtlFlags to Opened for driver DCE
  176.             JSR        (A2)                        ; JSR to this DRVR's Open Routine
  177.             
  178.             ; Sign-in device with the Sound Input Manager
  179.             
  180.             CLR.W    -(SP)                        ; result int
  181.             MOVE.W    D4,-(SP)                    ; ioRefNum of this DRVR  
  182.                                                 
  183.             LEA        @deviceName,A0
  184.             MOVE.L    A0,-(SP)                    ; Ptr to device name
  185.             _CallSoundIn    SPBSignInDevice        ; this macro is found in Traps.a
  186.             MOVE.W    (SP)+,D0
  187.             
  188. @outOfHere    
  189.             RTS
  190.         
  191.             STRING        PASCAL
  192. @drvrName    DC.B        '.HackRecorder'            ; driver name
  193. @deviceName    DC.B        'HackRecorder'            ; input device name
  194.             ALIGN        2
  195.  
  196. ;_______________________________________________________________________
  197. ;
  198. ; Routine:        ResizeUnitTable
  199. ;
  200. ; Stack Params:    
  201. ;                (Word)    --    Requested Size of Unit Table IN SLOTS (not bytes)
  202. ;
  203. ; Registers Used:
  204. ;                
  205. ;                
  206. ;
  207. ;_______________________________________________________________________
  208.             
  209.             EXPORT    ResizeUnitTable
  210.             
  211. ResizeUnitTable    
  212.             LINK    A6,#0
  213.             MOVEM.L    A0-A1/D1, -(SP)            ; Save used registers.            
  214.             
  215.             MOVE.W    8(A6), D1                    ; Get Size in SLOTS
  216.             MOVE.W    D1, D0
  217.             MULU.W    #4, D0                        ; turn into size in bytes
  218.             _NewPtr    ,sys,clear                    ; crate clear block in sys heap
  219.             BNE.S    @MemoryError                ; D0 contains error code, A0 contains Ptr
  220.             
  221.             MOVE    SR, -(SP)                    ; Save old SR
  222.             ORI        #Lvl7Mask, SR                ; disable interrupts
  223.             MOVEA.L    A0, A1                        ; put ptr to new table into A1
  224.             MOVEA.L UTableBase, A0                ; put ptr to old table into A0
  225.             MOVE.W    UnitNtryCnt, D0                ; get number of entries in old table
  226.             MULU.W    #4, D0                        ; size of old table
  227.             _BlockMove                            ; copy old table to new table
  228.             _DisposPtr                            ; get rid of old table
  229.             MOVE.L    A1, UTableBase                ; update UTableBase
  230.             MOVE.W    D1, UnitNtryCnt                ; update number of entries
  231.             MOVE    (SP)+, SR                    ; restore old interrupt status
  232.             CLR.L    D0                            ; return noErr
  233.             
  234. @MemoryError
  235.             
  236.             MOVEM.L    (SP)+, A0-A1/D1            ; Restore used registers.
  237.             UNLK    A6
  238.             RTS
  239.             
  240.             EndProc            
  241.  
  242.             End
  243.